package com.nju.bean.newsbangserver;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LogMaker {
	static File logFile;
	private LogMaker(){
		String time = getDateTime().replace(':', '-');
		logFile = new File("res/log/"+time+".log");
		makeLog("start to record...");
	}
	synchronized static public String makeLog(String str){
		
		if(logFile==null)
			new LogMaker();
		
		str = getDateTime()+": " + str;
		System.out.println(str);
	    try {
			BufferedWriter output = new BufferedWriter(new FileWriter(logFile,true));
			output.write(str+"\r\n");
			output.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return str;
	}
	
	public static String getDateTime(){
		SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return dateFormat.format(new Date());
	}	
}
